cmake_minimum_required(VERSION 3.10)

project(myproject)

#设置c++版本
set(CMAKE_CXX_STANDARD 14)

#头文件
include_directories(${PROJECT_SOURCE_DIR}/inc)
include_directories(/usr/include/hiredis)

#设置源文件
aux_source_directory(${PROJECT_SOURCE_DIR}/src src_list)
aux_source_directory(${PROJECT_SOURCE_DIR}/main_src main_list)

#查找静态库
#查找 hiredis 库（动态库）
find_library(redis_lib 
    NAMES hiredis 
    PATHS 
        /usr/lib/x86_64-linux-gnu  # 指定实际库路径
        /usr/local/lib 
        /usr/lib 
    NO_DEFAULT_PATH  # 仅在指定路径中搜索
)

# 检查是否找到库
if(NOT redis_lib)
    message(FATAL_ERROR "hiredis library not found")
else()
    message(STATUS "Found hiredis library: ${redis_lib}")
endif()

#设置生成的文件位置
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

#生成可执行文件
add_executable(app ${src_list} ${main_list})

#静态库
target_link_libraries(app ${redis_lib})